export default function ({ route, store, redirect, from, app, error }) {
  const { authInfo } = store.state
  const unneededLogin = ['index', 'login', 'topic', 'career-plan', 'plain', 'step', 'about', 'volunteer', 'xuankecode']
  const unneededVip = ['user-center', 'zhiyuan'] // 需要登录但不用vip权限
  const { token, dataFlag, isValid, level } = authInfo
  if (unneededLogin.indexOf(route.name) < 0) {
    if (!token) {
      return redirect('/login?type=login')
    }
    if (unneededVip.indexOf(route.name) < 0) {
      /* 未完善信息 */
      if (!dataFlag) return redirect('/login?step=2')
      /* 会员等级不存在  没有绑定会员卡 */
      // if (!level) return redirect('/login?step=3')
      if (!level) return redirect('/')
      /* 判断进入选科权限 */
      if (route.fullPath.indexOf('xuanke') > -1) {
        if ((level === 'FULL_FEATURED' || level === 'XUAN_KE') && isValid) {
        } else {
          error({
            statusCode: 402,
            message: '您当前VIP类型暂无访问选科权限。'
          })
        }
      }
      /* 判断进入志愿权限 */
      // if (route.fullPath.indexOf('zhiyuan') > -1) {
      //   if ((level === 'ZHI_YUAN' || level === 'FULL_FEATURED' || level === 'EXPERIENCE') && isValid) {
      //   } else {
      //     error({
      //       statusCode: 402,
      //       message: '您当前VIP类型暂无访问志愿权限。'
      //     })
      //   }
      // }
    } else {
      if (!dataFlag) return redirect('/login?step=2')
    }
  }
}
